#!/bin/bash

langlist="/etc/alterator/sysconfig/lang/langlist.all"
langlist_temp="$langlist".temp
locales="$GLOBAL_LOCALES"
locale="$GLOBAL_LOCALE"
systemd_locale=/etc/locale.conf
sysv_locale=/etc/sysconfig/i18n

if [ -f "$langlist" ] && [ -n "$locales" ]; then
	rm -f "$langlist_temp"

	for lang in $locales; do
		grep -q "$lang" "$langlist" && grep "$lang" "$langlist" >> "$langlist_temp"
	done

	mv "$langlist_temp" "$langlist"
fi

if [ -n "$locale" ]; then
	echo LANG="$locale".UTF8 > "$systemd_locale"
	echo LANG="$locale".UTF8 > "$sysv_locale"
	echo SUPPORTED="$locale".UTF8 >> "$sysv_locale"
fi
